package com.sangmo.fts.api.teacher;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.common.security.meta.Access;
import com.sangmo.fts.teacher.interfaces.ScoreSettingCreation;
import com.sangmo.fts.teacher.interfaces.ScoreSettingUpdate;
import com.sangmo.fts.teacher.model.ScoreSetting;
import com.sangmo.fts.teacher.service.ScoreSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

@Controller
@RequestMapping("/scoreSetting/v1")
@Access("scoreSetting")
public class ScoreSettingApi {

    @Autowired
    private ScoreSettingService scoreSettingService;

//    @Access(":create")
//    @PostMapping(value = "/create")
//    public @ResponseBody
//    ApiResponse<ScoreSetting> create(@RequestBody @Valid ScoreSettingCreation obj) {
//        return ApiResponse.make(scoreSettingService.create(obj));
//    }

    @Access(":update")
    @PostMapping("/{id}/update")
    public @ResponseBody ApiResponse<ScoreSetting> update(@PathVariable("id") Long id, @RequestBody @Valid ScoreSettingUpdate co) {
        return ApiResponse.make(scoreSettingService.update(id, co));
    }

//    @Access(":read")
    @PostMapping("/settingInfo")
    public @ResponseBody ApiResponse<ScoreSetting> settingInfo() {
        return ApiResponse.make(scoreSettingService.findByUserId());
    }
}
